package com.beyond.pm.ui.setting.system

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.NavigationDrawerItem
import androidx.compose.material3.NavigationDrawerItemDefaults
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.TopAppBarScrollBehavior
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.beyond.common.constant.VERSIONS_AND_UPDATES
import com.beyond.pm.R
import com.beyond.pm.bean.RouteScreenParameter
import com.beyond.pm.component.MyTopBar
import com.beyond.pm.component.MyTopBarStyle
import com.beyond.pm.local.LocalNavController
import com.beyond.pm.local.AppNavHostController

/**
 * @author chen
 * @time 2023/6/14 17:21
 * @name ProjectManage
 * @class describe
 */
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SystemSettingScreen() {
    val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior()
    val nav = LocalNavController.current
    val appNav = remember(nav) { AppNavHostController(nav) }
    Scaffold(
        topBar = {
            MyTopBar(
                style = MyTopBarStyle.Large,
                scrollBehavior = scrollBehavior,
                title = { Text(text = stringResource(R.string.system_setting)) }
            )
        }
    )
    {
        SystemSettingContent(it, scrollBehavior, appNav)
    }

}

private val systemSettings = listOf(
    RouteScreenParameter.Style,
    RouteScreenParameter.Language,
    RouteScreenParameter.Version,

)

@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun SystemSettingContent(
    paddingValues: PaddingValues,
    scrollBehavior: TopAppBarScrollBehavior,
    nav: AppNavHostController,
) {
    LazyColumn(
        modifier = Modifier
            .fillMaxSize()
            .padding(paddingValues)
            .nestedScroll(scrollBehavior.nestedScrollConnection),
        horizontalAlignment = Alignment.CenterHorizontally,
        verticalArrangement = Arrangement.spacedBy(10.dp)
    ) {
        itemsIndexed(systemSettings) { _, item ->
            NavigationDrawerItem(
                label = { Text(stringResource(id = item.bean.labelId)) },
                icon = { Icon(item.bean.icon, null) },
                selected = false,
                onClick = {
                    nav.navigate(item.bean.routerStr)
                },
                badge = {
                    if (item.bean.routerStr == VERSIONS_AND_UPDATES)
                        Text(text = "V1.0")
                },
                modifier = Modifier.padding(NavigationDrawerItemDefaults.ItemPadding)
            )
        }
    }
}